const car = {
	state: {
		carList: []
	},
	mutations: {
		setCarList(state, params) {
			let {
				item,
				num
			} = params;
			let caritem = {
				goodsid: item.id || item.goodsid, //item即是点击步进器所选择的商品
				name: item.name,
				numvalue: num, //步进器的值
				price: item.price,
				preprice: item.preprice,
				picurls: item.picurls
			};
			let index = state.carList.findIndex(car => {
				return car.goodsid == caritem.goodsid
			})
			if (index < 0) {
				state.carList.unshift(caritem);
			} else {
				state.carList[index].numvalue = caritem.numvalue;
				if (state.carList[index].numvalue <= 0) {
					state.carList.splice(index, 1);
				}
			}
		},
		clearCarList(state) {
			state.carList = [];
		}
	}
}
export default car
